<?
ini_set("display_errors","1");
ini_set("display_startup_errors","1");
ini_set('error_reporting', E_ALL);

	session_start();
  $servurl = "http://".$_SERVER['HTTP_HOST'];
  $error="";
  $errcount=0;


  //Checking fields and sending mail
  if(isset($_POST['go']))
  {

   		if($_POST['name']=='')
   		{
   			$error = $error.'<br>You have not entered a name!';
   		    $errcount = $errcount +1;

		}
		$name=$_POST['name'];

   		if($_POST['company']=='')
   		{
   			$error = $error.'<br>You have not entered company!';
   		    $errcount = $errcount +1;

		}
		$company=$_POST['company'];

   		if($_POST['email']=='')
   		{

   			$error = $error.'<br>You have not entered e-mail!';
   		    $errcount = $errcount +1;
   		}else{
			$email=$_POST['email'];
		}

   		if($_POST['phone']=='')
   		{
   			$error = $error.'<br>You have not entered phone!';
   		    $errcount = $errcount +1;
		}

		$phone=$_POST['email'];

   		if($_POST['subj']=='')
   		{
   			$error = $error.'<br>You have not entered subject!';
   		    $errcount = $errcount +1;
   		}

		$subj=$_POST['subj'];

   		if($_POST['message']=='')
   		{
   			$error = $error.'You have not entered message!';
   		    $errcount = $errcount +1;
   		}
		$message=$_POST['message'];

   		if($errcount == 0)
   		{
               $name = substr(htmlspecialchars($name), 0, 1000);
               $email = substr(htmlspecialchars($email), 0, 1000);
               $phone = substr(htmlspecialchars($phone), 0, 1000);
               $subj = substr(htmlspecialchars($subj), 0, 1000);
               $message = substr(htmlspecialchars($message), 0, 10000);

               $msg = "<b>Name:</b> ".$name."<br><br>";
               $msg = "<b>Company:</b> ".$company."<br><br>";
               $msg .= "<b>E-mail:</b> ".$email."<br><br>";
               $msg .= "<b>Phone:</b> ".$phone."<br><br>";
               $msg .= "<b>Subject:</b> ".$subj."<br><br>";
               $msg .= "<b>Message:</b> <br>".$message."<br><br>";

               $from="Vital Responce";
               $from_mail="VitalResponce@localhost";
               $to="contact@vresponse.com";
               $subject="Message from Vital Responce Rugs Contact Us form";

               $headers  = "Content-type: text/html; charset=windows-1251 \r\n";
				$headers .= "From: ".$from." <".$from_mail.">\r\n";
				$headers .= "Bcc: ".$from_mail."\r\n";
				$headers .= "X-Mailer: PHP/" . phpversion();

				if(mail($to, $subject, $msg, $headers))
				{
					$error = "Thank you for contacting us. We will be back with you shortly.";

				}
				else
				{
					$error = "Error during mail sending.";
				}


   		}

  }

  header("Location: $servurl/contact-us/?message=".urlencode($error));


?>
